home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / DataCopy / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  4.9 KB  |  170 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"            // CPizzaCommand
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWEVENTU_H
  31. #include "FWEventU.h"            // FW_IsCommandKeyPressed
  32. #endif
  33.  
  34. #ifndef FWCLPCMD_H
  35. #include "FWClpCmd.h"            // FW_CClipboardCommand
  36. #endif
  37.  
  38. #ifndef FWDRCMD_H
  39. #include "FWDrCmd.h"            // FW_CDragCommand, FW_CDropCommand
  40. #endif
  41.  
  42. #ifndef FWEVENT_H
  43. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  44. #endif
  45.  
  46. #ifndef FWKIND_H                // FW_CKind
  47. #include "FWKind.h"
  48. #endif
  49.  
  50. // ----- OS Layer -----
  51. #ifndef FWMENU_H
  52. #include "FWMenu.h"                // FW_CMenuBar, etc.
  53. #endif
  54.  
  55. #ifndef FWRECSHP_H
  56. #include "FWRecShp.h"            // FW_CRectShape
  57. #endif
  58.  
  59. //========================================================================================
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment DataCopy
  62. #endif
  63.  
  64. FW_DEFINE_AUTO(CDataCopyFrame)
  65.  
  66. //========================================================================================
  67. CDataCopyFrame::CDataCopyFrame(Environment* ev, ODFrame* odFrame, 
  68.                                 FW_CPresentation* presentation, CDataCopyContent* content)
  69.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  70.     FW_MDraggableFrame(ev, this),
  71.     FW_MDroppableFrame(ev, this),
  72.     fDataCopyContent(content)
  73. {
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. CDataCopyFrame::~CDataCopyFrame()
  78. {
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. FW_Handled 
  83. CDataCopyFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  84. {    
  85.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  86.     this->GetContentView(ev)->FrameToViewContent(ev, where);    
  87.     if (theMouseEvent.IsCopyModifier(ev)) {
  88.         this->Drag(ev, theMouseEvent);
  89.         }
  90.     else {
  91.         CPizzaCommand* cmd = FW_NEW(CPizzaCommand, (ev, cMakePizzaCmd, this, 
  92.                                                 fDataCopyContent, where) );
  93.         cmd->Execute(ev);
  94.         }
  95.     return true;
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. void 
  100. CDataCopyFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  101. {
  102.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  103.     FW_CRect invalidRect = FW_GetShapeBoundingBox(ev, invalidShape);
  104. //    FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kRGBLightGray);
  105.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  106.     
  107.     // draw pizzas
  108.     CPizzaCollection* list = fDataCopyContent->MyGetPizzaList();
  109.     CPizzaCollectionIterator iter(list);
  110.     CPizza* pizza = NULL;
  111.     ODShape* shape = NULL;
  112.     for (pizza = (CPizza*) iter.First(); iter.IsNotComplete(); pizza = (CPizza*) iter.Next()) {
  113.         if (::FW_IsCommandKeyPressed()) {
  114.             FW_CAcquiredODShape rectShape = ::FW_NewODShape(ev, pizza->GetBounds());
  115.             shape = rectShape->Intersect(ev, invalidShape);
  116.             if ( ! shape->IsEmpty(ev) ) 
  117.                 pizza->Draw(context);
  118.             }
  119.         else 
  120.             if (invalidRect.IsIntersecting( pizza->GetBounds() ) )
  121.                 pizza->Draw(context);
  122.         }
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. FW_CClipboardCommand* 
  127. CDataCopyFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)    // Override
  128. {
  129.     return FW_NEW(FW_CClipboardCommand, 
  130.             (ev, commandID, this, ! FW_kCanUndo) );
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. FW_Handled 
  135. CDataCopyFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  136.                                 FW_Boolean isRoot)    // Override
  137. {
  138.     FW_UNUSED(isRoot);
  139.     if (hasMenuFocus) {
  140.         FW_Boolean hasRightProperty = false;
  141.         FW_CKind* partKind = fDataCopyContent->GetPart(ev)->GetPartKind(ev);
  142.         ODType dataType = partKind->GetType(ev);
  143.         hasRightProperty = this->HasPropertyOnClipboard(ev, kODPropContents, dataType);
  144.         menuBar->EnableCommand(ev, kODCommandPaste, hasRightProperty);
  145.     }
  146.     return false;
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. FW_CDropCommand* 
  151. CDataCopyFrame::NewDropCommand(Environment *ev, 
  152.                                 FW_CFrame* frame,
  153.                                 ODDragItemIterator* dropInfo, 
  154.                                 ODFacet* facet, 
  155.                                 const FW_CPoint& dropPoint)    // Override
  156. {
  157.     return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, !FW_kCanUndo) );
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. FW_CDragCommand* 
  162. CDataCopyFrame::NewDragCommand(Environment *ev, 
  163.                                 FW_CFrame* theFrame, 
  164.                                 const FW_CMouseEvent& theMouseEvent)    // Override
  165. {
  166.     FW_UNUSED(theMouseEvent);
  167.     return FW_NEW(FW_CDragCommand, (ev, theFrame, !FW_kCanUndo));
  168. }
  169.  
  170.